// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.utils;

import java.io.Serializable;
import java.util.Arrays;

public class ExpandableBooleanList implements Serializable, Cloneable {
    private static final long serialVersionUID = 1L;
    private int width;
    private int bitWidth;
    private int[] value;

    public ExpandableBooleanList(int _width) {
        this.bitWidth = _width;
        this.width = _width / 32 + (_width % 32 != 0 ? 1 : 0);
        this.value = new int[this.width];
    }

    public ExpandableBooleanList clone() throws CloneNotSupportedException {
        ExpandableBooleanList expandableBooleanList0 = new ExpandableBooleanList(this.bitWidth);
        System.arraycopy(this.value, 0, expandableBooleanList0.value, 0, this.value.length);
        return expandableBooleanList0;
    }

    public void clear() {
        Arrays.fill(this.value, 0);
    }

    public void fill() {
        Arrays.fill(this.value, -1);
    }

    public boolean getValue(int x) {
        if (x >= 0 && x < this.bitWidth) {
            int int0 = x >> 5;
            int int1 = 1 << (x & 31);
            int int2 = this.value[int0];
            return (int2 & int1) != 0;
        } else {
            return false;
        }
    }

    public void setValue(int x, boolean newValue) {
        if (x >= 0) {
            if (x >= this.bitWidth) {
                int[] int0 = this.value;
                this.bitWidth = Math.max(this.bitWidth * 2, x + 1);
                this.width = this.bitWidth / 32 + (this.width % 32 != 0 ? 1 : 0);
                this.value = new int[this.width];
                System.arraycopy(int0, 0, this.value, 0, int0.length);
            }

            int int1 = x >> 5;
            int int2 = 1 << (x & 31);
            if (newValue) {
                this.value[int1] = this.value[int1] | int2;
            } else {
                this.value[int1] = this.value[int1] & ~int2;
            }
        }
    }

    public final int getWidth() {
        return this.width;
    }
}
